package org.jeecg.modules.business.mapper;

import java.util.List;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.jeecg.modules.business.entity.BusMarketCoupons;
import org.jeecg.modules.business.entity.BusMarketMealCoupons;
import org.jeecg.modules.business.entity.BusMarketMealCouponsUsed;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.jeecg.modules.business.vo.MealCouponStatVo;
import org.jeecg.modules.business.vo.MemberCardStatVo;

/**
 * @Description: bus_market_meal_coupons_used
 * @Author: jeecg-boot
 * @Date:   2023-03-14
 * @Version: V1.0
 */
public interface BusMarketMealCouponsUsedMapper extends BaseMapper<BusMarketMealCouponsUsed> {
    /**
     * 已核销餐券列表
     * @param hotelId
     * @param status
     * @param type
     * @return
     */
    @Select("<script>select u.*,c.name as coupons_name,cmc.name as type_name from bus_market_meal_coupons_used u\n" +
            "left join bus_market_meal_coupons_info c on c.id=u.coupons_id\n" +
            "left join bus_meal_coupon_info cmc on cmc.id=c.type where 1=1\n" +
            "<if test='hotelId != null and hotelId !=\"\"'> and u.hotel_id = #{hotelId} </if>"+
            "<if test='status >-1'> and u.status = #{status} </if>"+
            "<if test='type != null and type !=\"\"'> and c.type = #{type} </if>"+
            "</script>")
    public List<BusMarketMealCouponsUsed> verifyList(Page<BusMarketMealCouponsUsed> page, String hotelId, Integer status, String type);

    /**
     * 统计
     * @param hotelId
     * @return
     */
    @Select("<script>select ifnull(sum(CASE WHEN DATEDIFF(create_time,now())=0 THEN 1 ELSE 0 END),0) as day_count,\n" +
            "ifnull(sum(CASE WHEN DATEDIFF(used_time,now())=0 THEN 1 ELSE 0 END),0) as day_used_count,\n" +
            "ifnull(sum(CASE WHEN DATEDIFF(gain_time,now())=0 THEN 1 ELSE 0 END),0) as day_received_count,\n" +
            "/*ifnull(sum(CASE WHEN DATEDIFF(voided_time,now())=0 THEN 1 ELSE 0 END),0)*/ 0 as day_voided_count\n" +
            "from bus_market_meal_coupons_used u\n"+
            "left join bus_market_meal_coupons_info c on c.id=u.coupons_id\n" +
            "where u.hotel_id = #{hotelId}\n"+
            "<if test='type != null and type !=\"\"'> and c.type = #{type} </if>"+
            "</script>")
    public MealCouponStatVo stat(String hotelId,String type);
}
